<template>
  <view class="page">
    <view class="page-hd">
      <view class="search">
        <SearchBox
          :placeholder="$t('countTask.searchPlaceholder')"
          v-model="keyword"
        ></SearchBox>
      </view>

      <view class="link" @click="handlePreviousCount">
        <view class="icon icon-clock"></view>{{ $t('countTask.wangQiPanDian') }}
      </view>
    </view>

    <view class="page-bd">
      <!-- 盘点任务 -->
      <ListView :data="formatData" @operate="handleOperate" />
    </view>

    <CheckTaskCompleted
      v-model="showModal"
      v-if="showModal"
      @goCount="$tab.navigateTo(ROUTE.PAGE_APPS.START_COUNT, { test: '测试参数22' })"
    ></CheckTaskCompleted>
  </view>
</template>

<script setup>
import SearchBox from '@/components/base-components/search-box/search-box.vue';
import ListView from '@/components/base-components/list-view/list-view.vue';
import data from "./assets/list-view.data.js";
import useFormatData from './hooks/useFormatData.ts';
import { ROUTE } from '@/constant/constant';
import CheckTaskCompleted from './components/CheckTaskCompleted.vue';
import {checkSubOrderRequest} from '@/api/apps/apps.js';
import { getToken, setToken, removeToken } from "@/utils/auth";
import useUserStore from '@/store/modules/user';

const { proxy } = getCurrentInstance();
const [formatData] = useFormatData(data, []);
const showModal = ref(false);
const userStore = useUserStore();
function handleOperate(type, data) {
  if (type === 'startCount') {
    proxy.$tab.navigateTo(ROUTE.PAGE_APPS.START_COUNT, { test: '测试参数' })
  }
}

// 选择继续盘点
function handlePreviousCount() {
  // 跳转
  proxy.$tab.navigateTo(ROUTE.PAGE_APPS.PREVIOUS_COUNT, { test: '测试参数' })
}
// 检查子订单是否完成
const handleCheckSubOrder = () => {
  userStore.getInfo().then(res => {
    const userId = res.user.userId;
    checkSubOrderRequest(userId).then(res => {
      const type = res?.type;
      // 1 有未完成的子订单 0 没有未完成的子订单
      if (type == '1') {
        showModal.value = true;
      }
    });
  })
}

onMounted(() => {
  // 检查子订单是否完成
  handleCheckSubOrder();
});
</script>

<style scoped lang="scss">
@import "@/static/scss/theme.scss";
// $border-color: #E5E5EB;
// $theme-color: #1951FA;
// $error-color: #F53F3F;

.page {
  height: 100vh;
  background-color: #F4F8FB;

  &-hd {
    height: 104rpx;
    display: flex;
    align-items: center;
   padding: 0 30rpx;
    gap: 32rpx;
    background-color: #FEFEFF;
    .search {
      flex: 1;
      background-color: #F4F8FB;
    }

    .link {
      width: 144rpx;
      color: $theme-color;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 26rpx;
    }

    .icon-clock {
      flex-shrink: 0;
    }
  }

  &-bd {
    height: calc(100vh - 104rpx);
    margin: 16rpx 24rpx;
  }

  .navbar {
    height: 60rpx;
  }
}
</style>
